package com.genesis.yunnanji.utils;

import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;

/**
 * SharedPreference工具
 */
public class SPUtils {
    private static SPUtils spUtils;
    public static final String SpName = "GenesisSP";
    private SharedPreferences sp;
    Context context;


    private SPUtils(Context context) {
        this.context = context;
        sp = context.getSharedPreferences(SpName, Context.MODE_PRIVATE);
    }

    public static SPUtils getIntance(Context context) {
        if (spUtils == null) {
            spUtils = new SPUtils(context);
        }
        return spUtils;
    }

    public void putString(String key, String value) {
        Editor editor = sp.edit();
        editor.putString(key, value);
        editor.commit();
    }

    public String getString(String key, String defValue) {
        return sp.getString(key, defValue);
    }

    public void putBoolean(String key, boolean value) {
        Editor editor = sp.edit();
        editor.putBoolean(key, value);
        editor.commit();
    }

    public boolean getBoolean(String key, boolean defValue) {
        return sp.getBoolean(key, defValue);
    }

    public void setBoolean(String key, boolean value) {
        Editor et = sp.edit();
        et.putBoolean(key, value);
        et.commit();
    }

    public void putInt(String key, int value) {
        Editor editor = sp.edit();
        editor.putInt(key, value);
        editor.commit();
    }

    public int getInt(String key, int defValue) {
        return sp.getInt(key, defValue);
    }
}
